import React from 'react';
import { getCountry } from '@/service';

const useCountry = () => {
  const [countries, setCountries] = React.useState<{ value: string; label: string }[]>([]);

  async function fetchCounties() {
    const data = await getCountry('210100');
    if (data.success) {
      const cData = data.data.items.map(c => ({
        label: c.description,
        value: c.enum_value,
      }));
      setCountries(cData);
    }
  }

  React.useEffect(() => {
    fetchCounties();
  }, []);

  return countries;
};

export default useCountry;
